using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace Schedulr.Dialogs
{
    /// <summary>
    /// Allows the user to authenticate this application with Flickr.
    /// </summary>
    public partial class AuthenticationDialog : Form
    {
        /// <summary>
        /// The Flickr authentication URL.
        /// </summary>
        private string authenticationUrl;

        /// <summary>
        /// Initializes a new instance of the <see cref="AuthenticationDialog"/> class.
        /// </summary>
        /// <param name="authenticationUrl">The Flickr authentication URL.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "0#")]
        public AuthenticationDialog(string authenticationUrl)
        {
            InitializeComponent();
            this.authenticationUrl = authenticationUrl;
            this.authenticationWebBrowser.Navigate(this.authenticationUrl);
        }

        /// <summary>
        /// Handles the Click event of the okButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void okButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the cancelButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        /// <summary>
        /// Handles the LinkClicked event of the authenticationLinkLabel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.LinkLabelLinkClickedEventArgs"/> instance containing the event data.</param>
        private void authenticationLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(this.authenticationUrl);
        }
    }
}